// 计算倒计时
export function getCountdown(target) {
	const now = Date.now()
	const end = new Date(target).getTime()
	const diff = now - end

	if (diff <= 0) return {
		days: 0,
		hours: 0,
		minutes: 0,
		seconds: 0
	}

	return {
		days: Math.floor(diff / (1000 * 60 * 60 * 24)),
		hours: Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)),
		minutes: Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)),
		seconds: Math.floor((diff % (1000 * 60)) / 1000)
	}
}

// 日期格式化
export function formatDate(date) {
	return new Date(date).toISOString().split('T')[0]
}